define(function(require, exports, module) {

  var Backbone = require('backbone');
  var $ = require('jquery');
  var _ = require('underscore');
  var jsonview = require('jsonview');
  var tmpl = require('text!../tmpl.html');

  var __ = require('./klay.js')

  function main() {
    var $app = $('<div id="app">');
    $('#main').html($app);

    $app.append(tmpl);

    // assemble a graph
    var graph = {
      "id": "root",
      "properties": {
        "direction": "DOWN",
        "spacing": 40
      },
      "children": [{
        "id": "n1",
        "width": 40,
        "height": 40
      }, {
        "id": "n2",
        "width": 40,
        "height": 40
      }, {
        "id": "n3",
        "width": 40,
        "height": 40
      }],
      "edges": [{
        "id": "e1",
        "source": "n1",
        "target": "n2"
      }, {
        "id": "e2",
        "source": "n1",
        "target": "n3"
      }, {
        "id": "e3",
        "source": "n2",
        "target": "n3"
      }]
    };

    p.info(graph)

    // execute the layout

    $klay.layout({
      graph: graph,
      options: {
        spacing: 50
      },
      success: function(layouted) {
        p.info(layouted);
      },
      error: function(error) {
        p.info(error);
      }
    });
  }

  return main;
})
